package com.etong.frame.directive.impl.database;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.etong.frame.directive.DirectiveConfig;
import com.etong.frame.directive.factory.DirectiveFactory;
import com.etong.frame.directive.factory.DirectiveLoader;
import com.etong.frame.directive.factory.DirectiveManager;
import com.etong.framework.service.JSONRequest;

public class DirectiveLoaderImpl implements DirectiveLoader {

	private List<Map<String, Object>> directiveConfigs;
	private DirectiveFactory directiveFactory;

	@Override
	public boolean createDirecitives(DirectiveManager manager) {

		List<DirectiveConfig> directives = new ArrayList<DirectiveConfig>();
		for (Map<String, Object> configMap : directiveConfigs) {
			JSONRequest configJson = new JSONRequest(configMap);
			directives.add(configJson.to(Statement.class));
		}
		return manager.createDirectives(directives, directiveFactory);
	}

	public List<Map<String, Object>> getDirectiveConfigs() {
		return directiveConfigs;
	}

	public void setDirectiveConfigs(List<Map<String, Object>> directiveConfigs) {
		this.directiveConfigs = directiveConfigs;
	}

	public void setDirectiveFactory(DirectiveFactory directiveFactory) {
		this.directiveFactory = directiveFactory;
	}
}
